<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QTextObjectInterface Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTextObjectInterface Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QTextObjectInterface class allows drawing of custom text objects in <a href="qtextdocument.html">QTextDocument</a>s. <a href="#details">More...</a></p>
<p>Inherited by <a href="qpytextobject.html">QPyTextObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtextobjectinterface.html#QTextObjectInterface">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextobjectinterface.html#QTextObjectInterface-2">__init__</a></b> (<i>self</i>, QTextObjectInterface)</li><li><div class="fn" /><b><a href="qtextobjectinterface.html#drawObject">drawObject</a></b> (<i>self</i>, QPainter, QRectF, QTextDocument, int, QTextFormat)</li><li><div class="fn" />QSizeF <b><a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a></b> (<i>self</i>, QTextDocument, int, QTextFormat)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTextObjectInterface class allows drawing of custom text objects in <a href="qtextdocument.html">QTextDocument</a>s.</p>
<p>A text object describes the structure of one or more elements in a text document; for instance, images imported from HTML are implemented using text objects. A text object knows how to lay out and draw its elements when a document is being rendered.</p>
<p>Qt allows custom text objects to be inserted into a document by registering a custom <a href="qtextformat.html#objectType">object type</a> with <a href="qtextcharformat.html">QTextCharFormat</a>. A QTextObjectInterface must also be implemented for this type and be <a href="qabstracttextdocumentlayout.html#registerHandler">registered</a> with the <a href="qabstracttextdocumentlayout.html">QAbstractTextDocumentLayout</a> of the document. When the object type is encountered while rendering a <a href="qtextdocument.html">QTextDocument</a>, the <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a>() and <a href="qtextobjectinterface.html#drawObject">drawObject</a>() functions of the interface are called.</p>
<p>The following list explains the required steps of inserting a custom text object into a document:</p>
<ul>
<li>Choose an <i>objectType</i>. The <i>objectType</i> is an integer with a value greater or equal to <a href="qtextformat.html#ObjectTypes-enum">QTextFormat.UserObject</a>.</li>
<li>Create a <a href="qtextcharformat.html">QTextCharFormat</a> object and set the object type to the chosen type using the setObjectType() function.</li>
<li>Implement the QTextObjectInterface class.</li>
<li>Call <a href="qabstracttextdocumentlayout.html#registerHandler">QAbstractTextDocumentLayout.registerHandler</a>() with an instance of your QTextObjectInterface subclass to register your object type.</li>
<li>Insert <a href="qchar.html#SpecialCharacter-enum">QChar.ObjectReplacementCharacter</a> with the aforementioned <a href="qtextcharformat.html">QTextCharFormat</a> of the chosen object type into the document. As mentioned, the functions of QTextObjectInterface <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize()</a> and <a href="qtextobjectinterface.html#drawObject">drawObject()</a> will then be called with the <a href="qtextformat.html">QTextFormat</a> as parameter whenever the replacement character is encountered.</li>
</ul>
<p>A class implementing a text object needs to inherit both <a href="qobject.html">QObject</a> and QTextObjectInterface. <a href="qobject.html">QObject</a> must be the first class inherited. For instance:</p>
<pre> class SvgTextObject : public QObject, public QTextObjectInterface
 {
     Q_OBJECT
     Q_INTERFACES(QTextObjectInterface)</pre>
<p>The data of a text object is usually stored in the <a href="qtextcharformat.html">QTextCharFormat</a> using <a href="qtextformat.html#setProperty">QTextCharFormat.setProperty</a>(), and then retrieved with <a href="qtextformat.html#property">QTextCharFormat.property</a>().</p>
<p><b>Warning:</b> Copy and Paste operations ignore custom text objects.</p>
<p>See also <a href="richtext-textobject.html">Text Object Example</a>, <a href="qtextcharformat.html">QTextCharFormat</a>, and <a href="qtextlayout.html">QTextLayout</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTextObjectInterface" />QTextObjectInterface.__init__ (<i>self</i>)</h3><h3 class="fn"><a name="QTextObjectInterface-2" />QTextObjectInterface.__init__ (<i>self</i>, <a href="qtextobjectinterface.html">QTextObjectInterface</a>)</h3><h3 class="fn"><a name="drawObject" />QTextObjectInterface.drawObject (<i>self</i>, <a href="qpainter.html">QPainter</a>, <a href="qrectf.html">QRectF</a>, <a href="qtextdocument.html">QTextDocument</a>, int, <a href="qtextformat.html">QTextFormat</a>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Draws this text object using the specified <i>painter</i>.</p>
<p>The size of the rectangle, <i>rect</i>, to draw in is the size previously calculated by <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a>(). The rectangles position is relative to the <i>painter</i>.</p>
<p>You also get the document (<i>doc</i>) and the position (<i>posInDocument</i>) of the <i>format</i> in that document.</p>
<p>See also <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a>().</p>
<a name="//apple_ref/cpp/instm/QTextObjectInterface/intrinsicSize" />
<h3 class="fn"><a name="intrinsicSize" /><a href="qsizef.html">QSizeF</a> QTextObjectInterface.intrinsicSize (<i>self</i>, <a href="qtextdocument.html">QTextDocument</a>, int, <a href="qtextformat.html">QTextFormat</a>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>The intrinsicSize() function returns the size of the text object represented by <i>format</i> in the given document (<i>doc</i>) at the given position (<i>posInDocument</i>).</p>
<p>The size calculated will be used for subsequent calls to <a href="qtextobjectinterface.html#drawObject">drawObject</a>() for this <i>format</i>.</p>
<p>See also <a href="qtextobjectinterface.html#drawObject">drawObject</a>().</p>
<p /><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.7.1-5014f7c72a58 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt&#160;4.6.1</td></tr></table></div></address></body></html>